<!DOCTYPE html>
<html>
<head>
    <title>科普知识管理 - 垃圾分类系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 20px 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .header h1 {
            color: #2d3748;
            font-size: 28px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .header-actions {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
        }
        
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            text-decoration: none;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        
        .btn-success {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
            color: white;
        }
        
        .btn-success:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
        }
        
        .btn-danger {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            color: white;
        }
        
        .btn-danger:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
        }
        
        .btn-warning {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
            color: white;
        }
        
        .btn-warning:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);
        }
        
        .nav-tabs {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            padding: 8px;
            margin-bottom: 30px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            display: flex;
            gap: 4px;
            overflow-x: auto;
        }
        
        .nav-tab {
            padding: 12px 24px;
            border-radius: 12px;
            text-decoration: none;
            color: #718096;
            font-weight: 500;
            transition: all 0.3s ease;
            white-space: nowrap;
        }
        
        .nav-tab.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }
        
        .nav-tab:hover:not(.active) {
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
        }
        
        .page-title {
            color: white;
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 30px;
            text-align: center;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            animation: slideUp 0.6s ease-out;
        }
        
        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .add-article-section {
            margin-bottom: 30px;
            text-align: center;
        }
        
        .articles-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        
        .articles-table th,
        .articles-table td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #e5e7eb;
        }
        
        .articles-table th {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            font-weight: 600;
            color: #374151;
            font-size: 14px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        
        .articles-table tr:hover {
            background: rgba(102, 126, 234, 0.05);
        }
        
        .category-badge {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            color: white;
        }
        
        .category-recyclable {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        }
        
        .category-harmful {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        }
        
        .category-kitchen {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
        }
        
        .category-other {
            background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
        }
        
        .category-knowledge {
            background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
        }
        
        .article-title {
            font-weight: 600;
            color: #2d3748;
            max-width: 300px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        
        .article-content {
            max-width: 400px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            color: #6b7280;
        }
        
        .action-buttons {
            display: flex;
            gap: 8px;
        }
        
        .btn-sm {
            padding: 6px 12px;
            font-size: 12px;
        }
        
        .view-count {
            color: #6b7280;
            font-size: 14px;
        }
        
        .date-text {
            color: #6b7280;
            font-size: 14px;
        }
        
        .flash-messages {
            margin-bottom: 20px;
        }
        
        .flash-message {
            padding: 12px 20px;
            border-radius: 10px;
            margin-bottom: 10px;
            font-weight: 500;
        }
        
        .flash-success {
            background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
            color: #065f46;
            border: 1px solid #10b981;
        }
        
        .flash-error {
            background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
            color: #7f1d1d;
            border: 1px solid #ef4444;
        }
        
        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 16px;
                text-align: center;
            }
            
            .header-actions {
                justify-content: center;
            }
            
            .nav-tabs {
                justify-content: center;
            }
            
            .page-title {
                font-size: 24px;
            }
            
            .content-card {
                padding: 20px;
            }
            
            .articles-table {
                font-size: 14px;
            }
            
            .articles-table th,
            .articles-table td {
                padding: 10px 8px;
            }
            
            .action-buttons {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>📚 科普知识管理</h1>
            <div class="header-actions">
                <a href="/" class="btn btn-primary">🏠 返回前台</a>
                <a href="/logout" class="btn btn-danger">🚪 注销</a>
            </div>
        </header>
        
        <nav class="nav-tabs">
            <a href="/admin" class="nav-tab">📊 控制面板</a>
            <a href="/admin/users" class="nav-tab">👥 用户管理</a>
            <a href="/admin/knowledge" class="nav-tab active">📚 科普管理</a>
            <a href="/admin/forum" class="nav-tab">💬 社区管理</a>
            <a href="/admin/points_shop" class="nav-tab">🛒 积分商城</a>
            <a href="/admin/settings" class="nav-tab">⚙️ 系统设置</a>
        </nav>
        
        <h1 class="page-title">📚 科普知识管理</h1>
        
        <div class="content-card">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    <div class="flash-messages">
                        {% for category, message in messages %}
                            <div class="flash-message flash-{{ category }}">
                                {{ message }}
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}
            {% endwith %}
            
            <div class="add-article-section">
                <a href="/admin/knowledge/add" class="btn btn-success">➕ 添加新文章</a>
            </div>
            
            <table class="articles-table">
                <thead>
                    <tr>
                        <th>标题</th>
                        <th>分类</th>
                        <th>内容预览</th>
                        <th>浏览次数</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for article in articles %}
                    <tr>
                        <td>
                            <div class="article-title" title="{{ article.title }}">{{ article.title }}</div>
                        </td>
                        <td>
                            <span class="category-badge{% if article.category == '可回收垃圾' %} category-recyclable{% elif article.category == '有害垃圾' %} category-harmful{% elif article.category == '厨余垃圾' %} category-kitchen{% elif article.category == '其他垃圾' %} category-other{% else %} category-knowledge{% endif %}">
                                {{ article.category }}
                            </span>
                        </td>
                        <td>
                            <div class="article-content" title="{{ article.content[:100] }}...">
                                {{ article.content[:100] }}...
                            </div>
                        </td>
                        <td>
                            <span class="view-count">👁️ {{ article.view_count }}</span>
                        </td>
                        <td>
                            <span class="date-text">{{ article.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
                        </td>
                        <td>
                            <div class="action-buttons">
                                <a href="/knowledge/{{ article.id }}" class="btn btn-primary btn-sm" target="_blank">👁️ 预览</a>
                                <a href="/admin/knowledge/edit/{{ article.id }}" class="btn btn-warning btn-sm">✏️ 编辑</a>
                                <a href="/admin/knowledge/delete/{{ article.id }}" class="btn btn-danger btn-sm" 
                                   onclick="return confirm('确定要删除这篇文章吗？此操作不可撤销！')">🗑️ 删除</a>
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="6" style="text-align: center; color: #6b7280; padding: 40px;">
                            📝 暂无科普文章，<a href="/admin/knowledge/add" style="color: #667eea;">点击添加</a>第一篇文章
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>